package com.zy

import scala.collection.mutable.ArrayBuffer

/**
 * @description: 快学第三章
 * @author: zhaoyi
 * @create: 2020-04-23 19:51
 **/
object Chapter3 {

  def main(args: Array[String]): Unit = {
    val arr = new Array[Int](10)
    val array = Array(8, 9, 10)

    //indices所以的下标
    for (i <- array.indices) {
      print(i)
    }
    println()

    val arrayBuffer = ArrayBuffer(1, 2, 3)
    arrayBuffer.insert(0, -1, 0)
    arrayBuffer.+=(4)
    arrayBuffer.+=(5, 6, 7)
    //++=可以追加任何集合
    arrayBuffer.++=(array)

    println(arrayBuffer.mkString("[", ",", "]"))

    val ar = Array(12, 9, 10)
    //sorted并不改变原来的数组
    val sorted = ar.sorted
    println(ar.mkString(","))
    println(sorted.mkString("-"))
    //比较函数
    ar.sortWith((a, b) => a > b).foreach(print)
    println

    //多维数组,2行四列
    val ar24: Array[Array[Int]] = Array.ofDim(2, 4)
    ar24(0)(1) = 6
    ar24.foreach(r => println(r.mkString("[",",","]")))

    //不规多维数组
    val ar3 = new Array[Array[Int]](3)
    ar3(0) = Array(1)
    ar3(1) = Array(1,2)
    ar3(2) = Array(1,2,3)
    ar3.foreach(r => println(r.mkString("[",",","]")))

    /**
     * 调用java方法需要传入java的List，可以import JavaConversions.bufferAsJavaList
     *
     * 同时java方法返回List时候，
     *  可以import JavaConversions.asScalaBuffer将java的list转换城scala的bufferArray
     */
    val command = ArrayBuffer("ls","-al","/home/")
    import scala.collection.JavaConversions.bufferAsJavaList
    new ProcessBuilder(command)


  }

}
